import 'package:flutter/material.dart';
import 'package:pp_uikit/date_picker/pp_base_picker.dart';
import 'package:pp_uikit/theme/pp_picker_theme.dart';

// ignore: must_be_immutable
class PPPickerHeader extends StatelessWidget {
  TextStyle? confirmTextStyle;
  final DateVoidCallback onCancel, onConfirm;
  PPPickerHeader({
    Key? key,
    required this.onCancel,
    required this.onConfirm,
    this.confirmTextStyle,
  }) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return Container(
      height: PPPickerTheme.headerHeight,
      decoration: const ShapeDecoration(
        color: Colors.white,
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.only(
            topLeft: Radius.circular(PPPickerTheme.cornerRadius),
            topRight: Radius.circular(PPPickerTheme.cornerRadius),
          ),
        ),
      ),
      alignment: Alignment.center,
      child: Column(
        mainAxisSize: MainAxisSize.min,
        children: <Widget>[
          Container(
            height: PPPickerTheme.headerHeight - 0.5,
            padding: const EdgeInsets.symmetric(horizontal: 20),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: <Widget>[
                GestureDetector(
                  child: _cancelWidget(context),
                  onTap: () {
                    onCancel();
                  },
                ),
                Text(
                  "请选择",
                  style: PPPickerTheme.titleTextStyle,
                ),
                GestureDetector(
                  child: _confirmWidget(context),
                  onTap: () {
                    onConfirm();
                  },
                ),
              ],
            ),
          ),
          const Divider(
            color: PPPickerTheme.lineColor,
            indent: 0.0,
            height: 0.5,
          ),
        ],
      ),
    );
  }

  Widget _cancelWidget(BuildContext context) {
    Widget cancelWidget = Text(
      '取消',
      style: PPPickerTheme.cancelTextStyle,
      textAlign: TextAlign.left,
    );

    return cancelWidget;
  }

  Widget _confirmWidget(BuildContext context) {
    Widget confirmWidget = Text(
      '确定',
      style: confirmTextStyle ?? PPPickerTheme.confirmTextStyle,
      textAlign: TextAlign.right,
    );

    return confirmWidget;
  }
}
